
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
</head>
    <body>
    <input id="doctorcategoryid1" type="hidden" value="${doctor.doctorcategoryid}">
    <input type="hidden" id="sex1" value="${doctor.sex}"/>
    <form class="layui-form" id="formUpdate">

        <div class="layui-form-item">
            <input type="hidden" name="id" value="${doctor.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>性别</label>
            <div class="layui-input-inline typeSelect">
                <select name="sex" id="sex" lay-filter="sex"  >
                    <option value="">请选择</option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>医师类别</label>
                <div class="layui-input-inline typeSelect">
                    <select name="doctorcategoryid" id="doctorcategoryid" lay-filter="doctorcategoryid"  >
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>姓名</label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" class="layui-input" value="${doctor.name}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>手机号</label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone" class="layui-input" value="${doctor.phone}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" id="email" name="email" class="layui-input" value="${doctor.email}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>生日</label>
            <div class="layui-input-inline">
                <input type="text" id="birthday" class="layui-input" name="birthday" value="${doctor.birthday}"/>
            </div>
        </div>
        <button class="layui-btn" type="button" lay-filter="update" lay-submit="">保存修改</button>
        </div>
    </form>
    </body>

    <script type="text/javascript">
        layui.use(['form', 'layedit', 'layer','laydate'], function(){
            var $ = layui.$, form = layui.form,laydate=layui.laydate;
            laydate.render({
                elem: '#birthday'
            });
             $(function () {
          var sex=$("#sex1").val();
            // alert(typeof sex)
          if(sex=="1"){
              $("#sex [value='1']").attr("selected",true);
              // $("input[name='sex'][value=1]").attr("checked",true);
          }else{
              // $("input[name='sex'] [value=2]").attr("checked",true);
              $("#sex [value='2']").attr("selected",true);
          }
                     form.render();
      })
            //医师类别加载
             $(function () {
               var doctorcategoryid1=$("#doctorcategoryid1").val();
                 $.ajax({
                     type: 'post',
                     url: '/manage/doctor/SelDoctorCategory',
                     success:function(res){
                       if(res.length>0){
                           for(var i=0;i<=res.length;i++){
                               if(doctorcategoryid1==res[i].id){
                                   $("#doctorcategoryid").append("<option value='"+res[i].id+"' selected='selected'>"+res[i].type+"</option>")
                               }else{
                                   $("#doctorcategoryid").append("<option value='"+res[i].id+"'>"+res[i].type+"</option>")
                               }
                               form.render();     //重新渲染
                           }
                       }
                     }
                 });
             })
            // 监听提交
            form.on('submit(update)', function(){
                if($("#name").val().trim()=="" || $("#name").val().trim().length<0){
                    alert("姓名不能为空");
                    return false;
                }
                if($("#phone").val()=="" || $("#phone").val().length<0){
                    alert("号码不能为空");
                    return false;
                }
                if($("#birthday").val()=="" || $("#birthday").val().length<0){
                    alert("生日不能为空");
                    return false;
                }if($("#doctorcategoryid").val()=="" || $("#doctorcategoryid").val().length<0){
                    alert("医生类别不能为空");
                    return false;
                }if($("#sex").val()=="" || $("#sex").val().length<0){
                    alert("性别不能为空");
                    return false;
                }
                $.ajax({
                    url:'/manage/doctor/doctorUpdate',
                    type:'post',
                    data:$("#formUpdate").serialize(),
                    success:function(result){
                        alert(result);
                        window.parent.location.reload();
                    },
                    error:function(result){
                        alert("失败？请及时告知开发人员"+result);
                        window.parent.location.reload();
                    }
                });
            });
        });
    </script>
</html>